module sw.backup.backupmodelist;
import sw.mode, sw.contentmode, sw.unsupportedmode, sw.siteconfig, nazo.http, nazo.file, sw.utils, sw.cgiinfo, sw.modelist;
version(Wiki) import sw.wiki.preflist, sw.wiki.recentlist, sw.wiki.pagelist, sw.wiki.commentlist, sw.wiki.dat;
version(Upload) import sw.upload.uploadlist;

class BackupModeFactory:ModeFactory{
  mixin TModeFactory!();
  const static string prefix="backup";
  IMode getMode(string name){
    switch(name){
      version(Wiki){
        case "wiki:list":
          return new ListMode(cfg);
        case "wiki:recent":
          return new RecentMode(cfg);
        case "wiki:dat":
          return new DatMode(cfg);
        case "wiki:pref":
          return new PrefMode(cfg);
        case "wiki:comment":
          return new CommentMode(cfg);
      }
      version(Upload){
        case "upload:list":
          return new UploadListMode(cfg);
      }
      case "config":
        return new ConfigMode(cfg);
      case "info":
        return new InfoMode(cfg);
      default:
    }
    return new PlainUnsupportedMode(cfg);
  }
}

version(Wiki){
class ListMode:SourceMode{
  this(SiteConfig* cfg){
    super(cfg, PageList.getFileName);
  }
}

class PrefMode:SourceMode{
  this(SiteConfig* cfg){
    super(cfg, PrefList.getFileName(titleToFileName(getPageTitle(cfg))));
  }
}

class DatMode:SourceMode{
  this(SiteConfig* cfg){
    super(cfg, Dat.getFileName(titleToFileName(getPageTitle(cfg))));
  }
}

class RecentMode:SourceMode{
  this(SiteConfig* cfg){
    super(cfg, RecentList.getFileName);
  }
}

class CommentMode:SourceMode{
  this(SiteConfig* cfg){
    super(cfg, AllCommentList.getFileName);
  }
}
}

version(Upload){
class UploadListMode:SourceMode{
  this(SiteConfig* cfg){
    super(cfg, UploadList.getFileName);
  }
}
}

class ConfigMode:SourceMode{
  this(SiteConfig* cfg){
    super(cfg, cfg.fileName);
  }
}

class InfoMode:Mode!(){
  this(SiteConfig* cfg){
    super(cfg);
  }
  override void response(){
    auto info=new CgiInfo();
    HttpResponse.write("Version: " ~ info.ver ~ \n
                       "EnableOptions: " ~ info.enableOptions ~ \n
                       "CPUArch: " ~ info.cpuArch ~ \n
                       "CPUEndian: " ~ info.cpuEndian ,200,null);
  }
}
